package com.aat.dxfy.mq.t03;

import java.util.Properties;

import com.aliyun.openservices.ons.api.Action;
import com.aliyun.openservices.ons.api.ConsumeContext;
import com.aliyun.openservices.ons.api.Consumer;
import com.aliyun.openservices.ons.api.Message;
import com.aliyun.openservices.ons.api.MessageListener;
import com.aliyun.openservices.ons.api.ONSFactory;
import com.aliyun.openservices.ons.api.PropertyKeyConst;

public class ConsumerTest {
	public static void main(String[] args) {
		Properties properties = new Properties();
		properties.put(PropertyKeyConst.ConsumerId, "CID_dxytest_consumer01");
		properties.put(PropertyKeyConst.AccessKey, "LTAIDTzLNHcxuvSN");
		properties.put(PropertyKeyConst.SecretKey, "PLfJtT2aNetOVtzKUSurFcdUIk3Duh ");
		Consumer consumer = ONSFactory.createConsumer(properties);

		consumer.subscribe("dxytest", "*", new MessageListener() {
			@Override
			public Action consume(Message message, ConsumeContext context) {
				System.out.println("Receive: " + message);
				return Action.CommitMessage;
			}

		});
		consumer.start();
		System.out.println("Consumer Started");
	}
}
